#include "../Delta-Ray/state_men.h"

StateMenager::StateMenager(int a_tickrate){
    tick_per_s = a_tickrate;
    last_timer_update = clock();
    keep_alive=false;
}

void StateMenager::NewState(State *a_new, StateMenager *a_stmen,SDL_Surface *a_S_SCREEN){
    cur_state = a_new;
    cur_state->Init(a_stmen, a_S_SCREEN);
    keep_alive=true;
}

void StateMenager::TickState(){
    while(keep_alive == true){
        timer_cur = clock();
        if((timer_cur - last_timer_update) > (1000 / tick_per_s)){
            cur_state->Tick();
            last_timer_update = timer_cur;
        }
        cur_state->TickFast();
        cur_state->Draw();
    }
}

void StateMenager::EndState(){
    cur_state->Destroy();
    delete cur_state;
}

void StateMenager::UpdateAlive(bool a_op){
    keep_alive = a_op;
}

bool StateMenager::GetAlive(){
    return keep_alive;
}
